package com.jf.springmvc;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-10-30
 * Time:13:22
 */
@RequestMapping("/user")
@Controller
public class UserController {
    /*
    @RequestMapping
    1.可以注释类和方法,请求路径为http://ip:port/工程路径/类请求路径/方法请求路径
    2.仅配置路径时,value可以省略
    3.可以用method指定请求方式, 默认可以接受GET和POST请求
    4.常用请求方式GET POST DELETE PUT PATCH可以用@GetMapping @PostMapping @DeleteMapping @PutMapping @PatchMapping等价
    5.可以指定params
        param1--请求包含param1参数
        !=param1--请求不包含param1参数
        param1=value1--请求包含param1参数并且值必须为value1
        param1!=value1--请求包含param1参数并且值不能为value1
        {“param1","param2"}--请求包含param1和param2参数
    6.请求路径支持Ant风格资源地址
        ?--匹配一个字符  /user/create??? -> /user/createAAA | /user/createBBB ...
        *--匹配一层文件的任意字符 /user/'*'/create -> /user/aa/create | /user/bbb/create ...
        **--匹配多层文件任意字符 /user/'**'/create -> /user/aa/create | /user/aa/bbb/create
    7.配合@PathVariable映射Url绑定占位符  (无需在Url地址带参数,简洁化)
        注意: @PathVariable("param") 不能省略
    8.映射的Url不能有重复
     */
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public String login() {
        System.out.println("login");
        return "login_ok";
    }

    @GetMapping(value = "/search", params = "bookId")
    public String search(@RequestParam("bookId") String bookId) {
        System.out.println("bookId = " + bookId);
        return "success";
    }

    @GetMapping("/message/**")
    public String message() {
        System.out.println("message");
        return "success";
    }

    @GetMapping("/register/{username}/{password}")
    public String register(@PathVariable("username") String username, @PathVariable("password") String password) {
        System.out.println("username = " + username);
        System.out.println("password = " + password);
        return "success";
    }
}
